package com.s69.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.s69.entity.Book;
import com.s69.service.BookService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class BookController {

    @Resource
    private BookService bookService;

    @GetMapping("/list")
    public String list(Model model){
        List<Book> list = bookService.list();
        model.addAttribute("list",list);
        return "index";
    }

    @PostMapping("selectList")
    public String searchBooks(Model model,Book book){
       List<Book> list = bookService.searchBooks(book);
       model.addAttribute("list",list);
       return "index";
    }

    @GetMapping("/page")
    public String page(@RequestParam(defaultValue = "1") Integer pageNum, Model model){
        IPage Page=bookService.getPage(pageNum);
        model.addAttribute("page",Page);
        return "PageIndex";
    }

    @PostMapping("/del")
    public String del(Integer[] ids){
        if(ids.length > 0 ){
            bookService.del(ids);
        }
        return "redirect:/page";
    }

















}
